package sweet.helper.model

/** A trait that provide saving and loading from a properties file using
 * reflections injections.
 */
trait FilePropsModel extends ScalaReflection with Logger {
  import java.io._
  import sweet.helper._
      
  def loadFrom(file: File){
    val props = SProperties.loadFromXML(file)
    for((name,v) <- props){
      logger.debug("Invoking "+name+" setter with value "+v)
      val setter = setters(name)
      setter(v)
    }
  }
  def saveTo(file: File){    
    val props = SProperties()
    for((name,getter) <- getters){
      logger.debug("Invoking "+name+" getter")
      val v = getter()
      logger.debug("Value "+v)
      props(name) = v.toString
    }
    props.storeToXML(file, "ToolboxProject Data Model", "UTF-8")
  }
}

